# -*- coding: utf-8 -*-
__author__ = 'xuliliang'
# @Time    : 2018/11/14 下午6:19
# @Author  : 'xuliliang'
# @Email   : xuliliang@u51.com
# @File    : dao.py
# @Software: PyCharm


# -*- coding: UTF-8 -*-

import MySQLdb

from django.db import connection


class Dao(object):
    _CHART_DAYS = 560

    def getWorkChartsByMonth(self):
        cursor = connection.cursor()
        sql = "select date_format(create_time, '%%Y-%%m-%%d'),count(*) from sql_workflow where create_time>=date_add(now(),interval -%s day) group by date_format(create_time, '%%Y-%%m-%%d') order by 1 asc;" % (Dao._CHART_DAYS)
        cursor.execute(sql)
        result = cursor.fetchall()
        return result

    def getWorkChartsByPerson(self):
        cursor = connection.cursor()
        sql = "select engineer, count(*) as cnt from sql_workflow where create_time>=date_add(now(),interval -%s day) group by engineer order by cnt desc limit 50;" % (
            Dao._CHART_DAYS)
        cursor.execute(sql)
        result = cursor.fetchall()
        return result

    def execSql(self, sql):
        cursor = connection.cursor()
        cursor.execute(sql)
        result = cursor.fetchall()
        return result
